home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BIRTHSRC.ZIP / MODEX.INC < prev    next >
Encoding:
Text File  |  1993-11-23  |  12.0 KB  |  620 lines

  1. ;╔════════════════════════════════════════════════╗
  2. ;║  Name:Mode_X_(320x240)_Routines_______  V01.00 ║
  3. ;║                                                ║
  4. ;║  Modified:22-Nov-93                   FB ║
  5. ;╚════════════════════════════════════════════════╝
  6. ;
  7. ;  All code assumes that ES points to video segment!
  8. ;
  9. ;**************************************************
  10. ; Vars NOT defined in this INC file
  11. ;    WriteOffset:word
  12. ;    ClipMinX:word
  13. ;    ClipMinY:word
  14. ;    ClipMaxX:word
  15. ;    ClipMaxY:word
  16. ;    ClearColor:byte
  17.  
  18. ;General Regs
  19. MISC_OUTPUT        equ   03c2h
  20. MISC_OUTPUT_READ    equ   03cch
  21. FCW            equ   03dah
  22. FCR            equ   03cah
  23. INPUT_STATUS_0        equ   03c2h
  24. INPUT_STATUS_1        equ   03dah
  25.  
  26. ;Sequencer Regs
  27. SC_INDEX        equ   03c4h
  28. SC_DATA         equ   03c5h
  29. MAP_MASK        equ     02h
  30.  
  31. ;CRTC Regs
  32. CRTC_INDEX        equ   03d4h
  33. CRTC_DATA        equ   03d5h
  34.  
  35. ;Graphics Regs
  36. GC_INDEX        equ   03ceh
  37. GC_DATA         equ   03cfh
  38. READ_MAP        equ     04h
  39.  
  40. ;Attribute Regs
  41. ACW_FF            equ   03c0h
  42. ACR_FF            equ   03c1h
  43.  
  44. ;Color Regs
  45. PEL_GET         equ   03c7h
  46. PEL_SET         equ   03c8h
  47. PEL_DATA        equ   03c9h
  48.  
  49. START_ADDRESS_HIGH  equ     0ch   ;bitmap start address high byte
  50. START_ADDRESS_LOW   equ     0dh   ;bitmap start address low byte
  51.  
  52. tmppal    db 768 DUP (0)         ;temp palette
  53. DONE    dw 0             ;temp word
  54.  
  55. ; Sequencer Regs
  56. Sequencer   db 003h,021h,00fh,000h
  57. SeqEnd        db 006h
  58.  
  59. ; CRTC Regs
  60. CRTC        db    05fh,04fh,050h,082h,054h,080h,00dh,03eh
  61.         db    000h,041h,000h,000h,000h,000h,003h,0c0h
  62.         db    0eah,02ch,0dfh,028h,000h,0e7h,006h,0e3h
  63. CRTCEnd     db    0ffh
  64.  
  65. ; Graphics Regs
  66. Graphics    db    000h,000h,000h,000h,000h,040h,005h,00fh
  67. GraphicsEnd db    0ffh
  68.  
  69. ;Attribute Regs
  70. Attrib        db    041h,000h,00fh,000h
  71. AttribEnd   db    000h
  72.  
  73. ;--------------------------------------------------------
  74. ;
  75. ; Scron - Sets ModeX 320x240x256
  76. ;    IN     : -
  77. ;   OUT     : -
  78. ;  Modified : ax,cx,dx,si,di
  79. ;  Vars Used: ClearColor
  80. ;
  81. Scron        PROC
  82.  
  83.     mov    dx,INPUT_STATUS_1
  84. Scron1:
  85.     in    al,dx
  86.     test    al,08h
  87.     jz    Scron1    ;vertical sync is active high (1 = active)
  88.  
  89.     ;turn screen off
  90.     mov    dx,SC_INDEX
  91.     mov    al,1
  92.     out    dx,al
  93.     inc    dx
  94.     in    al,dx
  95.     or    al,00100000b
  96.     out    dx,al
  97.  
  98.     mov    cx,5
  99.     mov    dx,ACW_FF
  100.     mov    si,offset AttribEnd
  101. Scron6:
  102.     mov    al,cl
  103.     add    al,2fh
  104.     out    dx,al
  105.     mov    al,cs:[si]
  106.     out    dx,al
  107.     dec    si
  108.     loop    Scron6
  109.  
  110.     mov    cx,10h        ;Bit 5 not set-> allow host access to pal
  111. Scron5:
  112.     mov    al,cl
  113.     dec    al
  114.     out    dx,al
  115.     out    dx,al
  116.     loop    Scron5
  117.  
  118.     mov    al,30h
  119.     out    dx,al
  120.  
  121.     mov    dx,SC_INDEX
  122.     mov     ax,0604h
  123.     out    dx,ax        ;disable chain4 mode
  124.     mov    ax,0100h
  125.     out    dx,ax        ;synchronous reset while setting Misc Output
  126.                 ; for safety, even though clock unchanged
  127.     ;General Regs
  128.     mov    dx,MISC_OUTPUT
  129.     mov    al,0e3h
  130.     out    dx,al
  131.  
  132.     mov    si,offset SeqEnd
  133.     mov    dx,SC_INDEX
  134.     mov    cx,5
  135. Scron2:
  136.     mov    al,cl
  137.     dec    al
  138.     mov    ah,cs:[si]
  139.     dec    si
  140.     out    dx,ax
  141.     loop    Scron2
  142.  
  143.     mov    si,offset CRTCEnd
  144.     mov    dx,CRTC_INDEX
  145.     mov    cx,19h
  146. Scron3:
  147.     mov    al,cl
  148.     dec    al
  149.     mov    ah,cs:[si]
  150.     dec    si
  151.     out    dx,ax
  152.     loop    Scron3
  153.  
  154.     mov    si,offset GraphicsEnd
  155.     mov    dx,GC_INDEX
  156.     mov    cx,9
  157. Scron4:
  158.     mov    al,cl
  159.     dec    al
  160.     mov    ah,cs:[si]
  161.     dec    si
  162.     out    dx,ax
  163.     loop    Scron4
  164.  
  165.     mov    dx,SC_INDEX
  166.     mov     ax,0f02h
  167.     out    dx,ax            ;enable writes to all four planes
  168.  
  169.     sub    di,di            ;point ES:DI to display memory
  170.     mov    al,[ClearColor]
  171.     mov    ah,al
  172.     mov    cx,8000h        ;# of words in display memory
  173.     rep    stosw            ;clear all of display memory
  174.  
  175.     mov    dx,03c4h        ;turn screen on again
  176.     mov    ax,0101h
  177.     out    dx,ax
  178.  
  179.     ret
  180.  
  181. Scron           ENDP
  182.  
  183. ;--------------------------------------------------------
  184. ;
  185. ; Scroff  - Leaves ModeX
  186. ;    IN     : -
  187. ;   OUT     : -
  188. ;  Modified : ax,dx
  189. ;  Vars Used: -
  190. ;
  191.  
  192. Scroff        PROC
  193.  
  194.     mov    dx,03c4h
  195.     mov    al,1
  196.     out    dx,al
  197.     inc    dx
  198.     in    al,dx
  199.     or    al,00100000b
  200.     out    dx,al
  201.     mov    dx,INPUT_STATUS_1
  202. WaitVS:
  203.     in    al,dx
  204.     test    al,08h
  205.     jz    WaitVS    ;vertical sync is active high (1 = active)
  206.  
  207.     push    ds
  208.     push    0000
  209.     pop    ds
  210.     ;we didn't use int10h to set video mode
  211.     ;so we the old mode # is still set in
  212.     ;BIOS data area.
  213.     mov    al,ds:[0449h]        ;get previous mode
  214.     mov    ah,00h
  215.     int    10h
  216.     pop    ds
  217.     ret
  218.  
  219. Scroff          ENDP
  220.  
  221. ;--------------------------------------------------
  222. ;
  223. ; ScrClear  - Clears 320x240 Window
  224. ;    IN     : -
  225. ;   OUT     : -
  226. ;  Modified : ax,cx,dx,di
  227. ;  Vars Used: WriteOffset,ClearColor
  228. ;
  229.  
  230. ScrClear    PROC
  231.  
  232.     mov     dx,SC_INDEX
  233.     mov     ax,0f02h
  234.     out    dx,ax            ;enable writes to all four planes
  235.     mov    di,[WriteOffset]    ;point ES:DI to display memory
  236.     mov    al,[ClearColor]
  237.     mov    ah,al
  238.     mov    cx,2580h        ;# of words
  239.     cld
  240.     rep     stosw    ;clear all of page
  241.  
  242.     ret
  243.  
  244. ScrClear        ENDP
  245.  
  246. ;--------------------------------------------------
  247. ; BoxClear  - Clears Window on 4-pixel boundary
  248. ;    IN     : cx   (XPos div 4)
  249. ;          dx   (YPos)
  250. ;          ax   (XLen div 4)
  251. ;          bx   (YLen)
  252. ;   OUT     : -
  253. ;  Modified : ax,bx,cx,dx,di,es
  254. ;  Vars Used: WriteOffset,ClearColor
  255. ;
  256. ;Note: This only clears on 4-pixel boundaries! - but FAST!
  257.  
  258. BoxClear    PROC
  259.  
  260.  
  261.     xor    edi,edi
  262.     mov    di,dx
  263.     shl    di,4                ;multiply by 16
  264.     lea    edi,[edi+4*edi]         ;multiply by 5
  265.     add    di,cx
  266.     add    di,[WriteOffset]        ;point ES:DI to display memory
  267.     mov    dx,80
  268.     sub    dx,ax
  269.     mov    cx,ax
  270.     cld
  271.     mov    dx,SC_INDEX
  272.     mov     ax,0f02h
  273.     out    dx,ax                ;enable writes to all four planes
  274.  
  275.     mov    al,[ClearColor]
  276.  
  277. boxclear1:
  278.     push    cx
  279.     rep    stosb                ;clears horizontal line
  280.     pop    cx
  281.     add    di,dx
  282.     dec    bx
  283.     jnz    boxclear1
  284.  
  285.     ret
  286.  
  287. BoxClear    ENDP
  288.  
  289. ;--------------------------------------------------
  290. ; ClearVGAMem  - Clears VGA Video Memory
  291. ;    IN     : -
  292. ;   OUT     : -
  293. ;  Modified : ax,cx,dx,di,es
  294. ;  Vars Used: ClearColor
  295.  
  296. ClearVGAMem    PROC
  297.  
  298.     mov     dx,SC_INDEX
  299.     mov     ax,0f02h
  300.     out    dx,ax            ;enable writes to all four planes
  301.     sub    di,di            ;point ES:DI to display memory
  302.     mov    al,[ClearColor]
  303.     mov    ah,al
  304.     mov    cx,8000h        ;# of words in display memory
  305.     cld
  306.     rep    stosw            ;clear all of display memory
  307.  
  308.     ret
  309.  
  310. ClearVGAMem     ENDP
  311.  
  312. ;--------------------------------------------------
  313. ; SetDot - Sets Dot/Pixel - with clipping
  314. ;    IN     : cx   (XPos)
  315. ;          dx   (YPos)
  316. ;          al   (Color)
  317. ;   OUT     : -
  318. ;  Modified : bx,cx,dx,es
  319. ;  Vars Used: WriteOffset
  320. ;
  321.  
  322. SetDot        PROC
  323.  
  324.     cmp    dx,[ClipMaxY]
  325.     jae    NoDot
  326.     cmp    dx,[ClipMinY]
  327.     jb    NoDot
  328.  
  329.     cmp    cx,[ClipMaxX]
  330.     jae    NoDot
  331.     cmp    cx,[ClipMinX]
  332.     jb    NoDot
  333.  
  334.     push    ax
  335.     xor    eax,eax
  336.     mov    ax,dx
  337.     ;multyply by 80
  338.     shl    ax,4        ;multiply by 16
  339.     lea    eax,[eax+4*eax] ;multiply by 5
  340.  
  341.     mov    bx,cx
  342.     shr     bx,2
  343.     add    bx,ax            ;offset of pixel in page
  344.     add    bx,[WriteOffset]    ;offset of pixel in display memory
  345.  
  346.     and    cl,011b         ;pixel's plane
  347.     mov    ax,0100h + MAP_MASK    ;AL = index in SC of Map Mask reg
  348.     shl    ah,cl        ;set only the bit for the pixel's plane to 1
  349.     mov     dx,SC_INDEX ;set the Map Mask to enable only the
  350.     out    dx,ax        ; pixel's plane
  351.  
  352.     pop    ax
  353.     mov    es:[bx],al  ;draw the pixel in the desired color
  354. NoDot:
  355.     ret
  356. SetDot        ENDP
  357.  
  358. ;--------------------------------------------------
  359. ; GetDot - Gets Dot/Pixel
  360. ;    IN     : cx   (XPos)
  361. ;          dx   (YPos)
  362. ;   OUT     : ax   (Color)
  363. ;  Modified : bx,cx,dx,es
  364. ;  Vars Used: WriteOffset
  365. ;
  366.  
  367. GetDot           PROC
  368.  
  369.     xor    eax,eax
  370.     mov    ax,dx
  371.     shl    ax,4        ;multiply by 16
  372.     lea    eax,[eax+4*eax] ;multiply by 5
  373.     mov    bx,cx
  374.     shr    bx,2
  375.     add    bx,ax             ;offset of pixel in page
  376.     add    bx,[WriteOffset]     ;offset of pixel in display memory
  377.  
  378.     mov    ah,cl
  379.     and    ah,011b          ;AH = pixel's plane
  380.     mov    al,READ_MAP         ;AL = index in GC of the Read Map reg
  381.     mov    dx,GC_INDEX         ;set the Read Map to read the pixel's
  382.     out    dx,ax             ; plane
  383.  
  384.     mov    al,es:[bx]         ;read the pixel's color
  385.     sub    ah,ah             ;convert it to an unsigned int
  386.  
  387.     ret
  388.  
  389. GetDot           ENDP
  390.  
  391. ;--------------------------------------------------
  392. ; SetCol - Sets Color Register
  393. ;    IN     : al   (ColReg)
  394. ;          ah   (Red)
  395. ;          bl   (Green)
  396. ;          bh   (Blue)
  397. ;   OUT     : -
  398. ;  Modified : ax,bx,dx
  399. ;  Vars Used: -
  400.  
  401. SetCol      PROC
  402.  
  403.       mov    dx,PEL_SET
  404.       out   dx,al
  405.  
  406.       inc   dx
  407.  
  408.       mov    al,ah
  409.       out   dx,al
  410.       mov    al,bl
  411.       out   dx,al
  412.       mov    al,bh
  413.       out   dx,al
  414.  
  415.       ret
  416.  
  417. SetCol    ENDP
  418.  
  419. ;--------------------------------------------------
  420. ; SetPal - Sets Color Palette
  421. ;    IN     : ds:si   (Ptr to Palette)
  422. ;          al   (ColReg - Start)
  423. ;          cx   (Range)
  424. ;   OUT     : -
  425. ;  Modified : ax,cx,dx,si
  426. ;  Vars Used: -
  427. SetPal        PROC
  428.  
  429.     mov    dx,PEL_SET
  430.     out    dx,al
  431.  
  432.     cld
  433.     mov    dx,cx
  434.     shl    cx,1
  435.     add    cx,dx            ;cx=cx*3
  436.  
  437.     mov    dx,INPUT_STATUS_1
  438. WaitVS1:
  439.     in    al,dx
  440.     test    al,08h
  441.     jz    WaitVS1         ;vertical sync is active high (1 = active)
  442.     mov    dx,PEL_SET+1
  443.  
  444. palwrite:
  445.     outsb                ;very fast V-cards don't like rep outsb
  446.     loop palwrite
  447.  
  448.     ret
  449.  
  450. SetPal        ENDP
  451. ;--------------------------------------------------
  452. ; FadeIn - Fades Current Palette into New Palette
  453. ;    IN     : ds:si   (Ptr to (should-be) Palette)
  454. ;          al   (From ColReg)
  455. ;          ah   (Stepsize)
  456. ;          cx   (Range)
  457. ;   OUT     : -
  458. ;  Modified : ax,bx,cx,dx,si,di,bp
  459. ;  Vars Used: tmppal (local cs)
  460. FadeIn        PROC
  461.  
  462.     mov    dx,PEL_SET-1    ;PEL Read Mode Reg
  463.     out    dx,al        ;start reading PEL data from color entry FR_COL
  464.  
  465.     mov    dx,cx
  466.     shl    cx,1
  467.     add    cx,dx        ;cx=cx*3
  468.     mov    dx,PEL_SET+1    ;PEL Data Reg
  469.  
  470.     mov    bp,cx
  471.     mov    di,offset tmppal
  472.     cld
  473.  
  474.     push    es
  475.     push    cs
  476.     pop    es
  477. fadein5:
  478.     insb              ;read PEL data
  479.     loop    fadein5
  480.     pop    es
  481.  
  482.     xor    ecx,ecx
  483.     mov    cl,al
  484.     lea    ecx,[ecx+2*ecx]
  485.  
  486.     mov    di,offset tmppal
  487.     add    si,cx
  488.     add    di,cx
  489.     xchg    di,si
  490.     mov    cx,bp
  491.  
  492. fadeagain:
  493.        ;mov    dx,PEL_SET    ;PEL Read Mode Reg
  494.        ;out    dx,al        ;start reading PEL data from color entry FR_COL
  495.  
  496.     xor    bp,bp        ;number of colregs that actually changed
  497.  
  498.     push    si
  499.     push    di
  500.     push    cx
  501. fadein1:
  502.     mov    al,byte ptr [di]      ;should-be-value
  503.     mov    bl,byte ptr cs:[si]
  504.     sub    bl,al            ;compare with is-value
  505.     je    fadein2         ;reached destination value?
  506.     jb    fadein3
  507.  
  508.     cmp    bl,ah
  509.     jge    fadein7
  510.     mov    byte ptr cs:[si],al
  511.     jmp    short fadein4
  512. fadein7:
  513.     sub    byte ptr cs:[si],ah    ;should-be-value < is-value
  514.     jmp    short fadein4
  515. fadein3:
  516.     neg    bl
  517.     cmp    bl,ah
  518.     jge    fadein8
  519.     mov    byte ptr cs:[si],al
  520.     jmp    short fadein4
  521. fadein8:
  522.     add    byte ptr cs:[si],ah
  523. fadein4:
  524.  
  525.     inc    bp
  526. fadein2:
  527.     inc    di
  528.     inc    si
  529.     loop    fadein1
  530.     pop    cx
  531.     pop    di
  532.     pop    si
  533.     or    bp,bp            ;have any colregs changed?
  534.     je    fadedone
  535.  
  536.     push    cx
  537.     push    si
  538.     mov    dx,INPUT_STATUS_1
  539. WaitVS2:
  540.     in    al,dx
  541.     test    al,08h
  542.     jz    WaitVS2         ;vertical sync is active high (1 = active)
  543.  
  544.     mov    dx,PEL_SET        ;PEL Read Mode Reg
  545.     mov    al,0
  546.     out    dx,al            ;start reading PEL data from color entry FR_COL
  547.  
  548.     mov    dx,PEL_SET+1        ;PEL Data Reg
  549. fadein6:
  550.     outs    dx,byte ptr cs:[si] ;do the deed
  551.     loop    fadein6
  552.  
  553.     pop    si
  554.     pop    cx
  555.     jmp    short fadeagain
  556. fadedone:
  557.     ret
  558.  
  559. FadeIn        ENDP
  560. ;--------------------------------------------------
  561. ; SetPage - Sets page to write to
  562. ;    IN     : ax   (WriteOffset)
  563. ;   OUT     : -
  564. ;  Modified : -
  565. ;  Vars Used: -
  566.  
  567. SetPage     PROC
  568.  
  569.     mov    [WriteOffset],ax
  570.     ret
  571.  
  572. SetPage         ENDP
  573.  
  574. ;--------------------------------------------------
  575. ; ShowPage - Sets page to show
  576. ;    IN     : ax   (DisplayStart)
  577. ;   OUT     : -
  578. ;  Modified : ax,bx,cx,dx
  579. ;  Vars Used: -
  580.  
  581. ;code originally from PC-Mag (?)
  582.  
  583. ShowPage    PROC
  584.  
  585. ; Wait for display enable to be active (status is active low), to be
  586. ; sure both halves of the start address will take in the same frame.
  587.     mov    cx,ax
  588.     mov     bh,cl
  589.     mov     bl,START_ADDRESS_LOW
  590.     mov     cl,START_ADDRESS_HIGH
  591.     mov     dx,INPUT_STATUS_1
  592. WaitDE:
  593.     in    al,dx
  594.     test    al,01h
  595.     jnz    WaitDE    ;display enable is active low (0 = active)
  596.  
  597. ; Set the start offset in display memory of the page to display.
  598.     mov     dx,CRTC_INDEX
  599.     mov     ax,bx
  600.     out     dx,ax   ;start address low
  601.     mov     ax,cx
  602.     out     dx,ax   ;start address high
  603.  
  604. ; Now wait for vertical sync, so the other page will be invisible when
  605. ; we start drawing to it.
  606.  
  607.        ;we are synchronized with VR, so we don't need this...
  608.  
  609.        ;mov    dx,INPUT_STATUS_1
  610. ;WaitVS3:
  611.        ;in    al,dx
  612.        ;test    al,08h
  613.        ;jz    WaitVS3 ;vertical sync is active high (1 = active)
  614.  
  615.        ret
  616. ShowPage       ENDP
  617.  
  618. ;--------------------------------------------------
  619. ;**************************************************
  620.